package com.macro.mall.portal.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.UmsMember;
import com.macro.mall.portal.service.TiTrainingService;
import com.macro.mall.portal.service.UmsMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * TiTraining的路由接口服务
 *
 * @author
 */
@Slf4j
@RestController
@RequestMapping("TiTrainingController")
@Api(tags = "专题信息表", description = "专题信息表")
public class TiTrainingController {

    /**
     * TiTrainingService服务
     */
    @Autowired
    private TiTrainingService tiTrainingService;
    @Autowired
    private UmsMemberService memberService;

    /**
     * 查询所有数据的方法
     *
     * @param
     * @return
     */
    @GetMapping(value = "/list", produces = {"application/json;charset=UTF-8"})
    public CommonResult find(@ApiParam(value="学院id") @RequestParam(value = "collegeId",required = false) String collegeId,
                             @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                             @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        UmsMember member = memberService.getCurrentMember();
        return CommonResult.success(CommonPage.restPage(tiTrainingService.find(member.getId(),collegeId, pageNum, pageSize)));
//        return CommonResult.success(CommonPage.restPage(tiTrainingService.find(10l,collegeId, pageNum, pageSize)));
    }

    /**
     * 通过id查询数据的方法
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/getById", produces = {"application/json;charset=UTF-8"})
    public CommonResult findOne(@RequestParam(name = "id") Integer id) {
        return CommonResult.success(tiTrainingService.findOne(id));
    }
}
